package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.repository;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.task.FlowActivityApproverVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FlowActivityAproverRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.entities.FlowActivityApprover;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.mapper.FlowActivityApproverDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: niechanggang
 * @date:2021/9/1 23:50
 * @description:
 */

@Repository
public class FlowActivityAproverRepositoryImpl implements FlowActivityAproverRepository {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FlowActivityApproverDAO  flowActivityApproverDAO;

    @Override
    public int insert(FlowActivityApproverVo flowActivityApproverVo) {
        FlowActivityApprover flowActivityApprover = new FlowActivityApprover();
        BeanUtils.copyProperties(flowActivityApproverVo, flowActivityApprover);
        int cnt = flowActivityApproverDAO.insertSelective(flowActivityApprover);
        return cnt;
    }

    @Override
    public List<FlowActivityApproverVo> selectByDeployIdAndActivityId(String deployId, String activityId) {
        List<FlowActivityApproverVo> flowActivityApproverVoList = new ArrayList<>();
        List<FlowActivityApprover>  approverList = flowActivityApproverDAO.selectByDeployIdAndActivityId(deployId, activityId);
        for(FlowActivityApprover approver : approverList){
            FlowActivityApproverVo vo = new  FlowActivityApproverVo();
            BeanUtils.copyProperties(approver, vo);
            flowActivityApproverVoList.add(vo);
        }
        return flowActivityApproverVoList;
    }
}
